package com.mmy.fta.usercenter.service.impl;

import com.mmy.fta.usercenter.api.CargoTimesDeductService;
import com.mmy.fta.usercenter.entity.ShipperMembershipEntity;
import com.mmy.fta.usercenter.repository.DriverInfoEntityMapper;
import com.mmy.fta.usercenter.repository.OpenidUserMapper;
import com.mmy.fta.usercenter.repository.ShipperInfoEntityMapper;
import com.mmy.fta.usercenter.repository.ShipperMembershipEntityMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Objects;

/**
 * @author guohao.xie
 * @apiNote
 * @exportable
 * @since 2021/11/5
 */

@Service
public class CargoTimesDeductServiceImpl implements CargoTimesDeductService {

    @Autowired
    OpenidUserMapper openidUserMapper;
    @Autowired
    ShipperInfoEntityMapper shipperInfoEntityMapper;
    @Autowired
    ShipperMembershipEntityMapper shipperMembershipEntityMapper;
    @Override
    public int cargoTimesDeductService(String openId) {
        int openidUserDeduct = openidUserMapper.updateShipperCargoTimes(openId);
        int shipperInfoDeduct = shipperInfoEntityMapper.updateShipperCargoTimesDeduct(openId);
        int membershipDeduct=shipperMembershipEntityMapper.updateDriverCargoTimesDeduct(openId);
        return 1;
    }

    @Override
    public int sendTimesAddService(String openId) {
        int shipperInfoAdd = shipperInfoEntityMapper.updateDriverCargoTimesAdd(openId);
        ShipperMembershipEntity isMembership = shipperMembershipEntityMapper.selectByOpenId(openId);
        if(Objects.nonNull(isMembership)){
            int membershipAdd = shipperMembershipEntityMapper.updateDriverCargoTimesAdd(openId);
        }

        return 1;
    }


}
